home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / KoPictureCollection.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-30  |  5.7 KB  |  172 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 1998, 1999 Reginald Stadlbauer <reggie@kde.org>
  3.    Copyright (c) 2001 David Faure <faure@kde.org>
  4.    Copyright (C) 2002 Nicolas GOUTTE <goutte@kde.org>
  5.  
  6.    This library is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU Library General Public
  8.    License as published by the Free Software Foundation; either
  9.    version 2 of the License, or (at your option) any later version.
  10.  
  11.    This library is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.    Library General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU Library General Public License
  17.    along with this library; see the file COPYING.LIB.  If not, write to
  18.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19.  * Boston, MA 02110-1301, USA.
  20. */
  21.  
  22. #ifndef koPictureCollection_h
  23. #define koPictureCollection_h
  24.  
  25. #include <qmap.h>
  26. #include <qdom.h>
  27. #include <qvaluelist.h>
  28.  
  29. #include "KoPicture.h"
  30.  
  31. class KURL;
  32.  
  33. class KoStore;
  34. class KoXmlWriter;
  35.  
  36. /**
  37.  * A collection of pictures (a key and the picture itself).
  38.  *
  39.  */
  40. class KOFFICECORE_EXPORT KoPictureCollection : public QMap<KoPictureKey, KoPicture>
  41. {
  42. public:
  43.     enum Type {
  44.         /// collection with mixed pictures
  45.         CollectionPicture=0,
  46.         /// collection with images only
  47.         CollectionImage,
  48.         /// collection with cliparts only
  49.         CollectionClipart
  50.     };
  51.  
  52.     /**
  53.      * Looks for a clipart in the collection, returns a new KoPicture with that key if not found.
  54.      */
  55.     KoPicture findPicture( const KoPictureKey &key ) const;
  56.  
  57.     /**
  58.      * Inserts a picture into the collection, if not already there
  59.      */
  60.     KoPicture insertPicture( const KoPictureKey& key, const KoPicture& picture );
  61.  
  62.     /**
  63.      * Inserts a picture into the collection, if not already there
  64.      * Same as above, but takes the key from the @p picture
  65.      */
  66.     KoPicture insertPicture( const KoPicture& picture );
  67.  
  68.     /**
  69.      * @brief Download a possibly remote file
  70.      *
  71.      * If this file is really remote, it is always downloaded.
  72.      * If the file is local, it acts as @ref #loadPicture.
  73.      * @param url the URL to download from
  74.      * @param window the parent window for the download. You can pass NULL (0)
  75.      *               if you absolutely cannot find anything to use.
  76.      */
  77.     KoPicture downloadPicture(const KURL& url, QWidget *window);
  78.  
  79.     /**
  80.      * @brief Load a clipart from a file (and insert into the collection).
  81.      *
  82.      * The modification date of the file is checked, to create the key
  83.      * for this clipart. If this key maps to an existing clipart in the
  84.      * collection, then this picture is returned, otherwise the file is loaded.
  85.      */
  86.     KoPicture loadPicture( const QString &fileName );
  87.  
  88.     /**
  89.      * Save the used picturess from the collection into the store
  90.      * Usually called from completeSaving().
  91.      *
  92.      * @param pictureType type for the stored picture
  93.      * @param store the store in which to save the pictures
  94.      * @param keys the list of keys corresponding to the pictures to save
  95.      * @return true on success, false on failure (e.g. disk full)
  96.      *
  97.      * @todo Reduce lameness of dox for pictureType.
  98.      */
  99.     bool saveToStore(const Type pictureType, KoStore * store, const QValueList<KoPictureKey>& keys );
  100.  
  101.     /**
  102.      * Generate the <PICTURES>, <PIXMAPS> or <CLIPARTS> tag, that saves the key and the related
  103.      * relative path in the store (e.g. pictures/picture1.png) for each picture.
  104.      *
  105.      * @param pictureType the type of the collection
  106.      * @param doc the DOM document in which the tags are to be generated
  107.      * @param keys the list of keys
  108.      */
  109.     QDomElement saveXML(const Type pictureType, QDomDocument &doc,
  110.         QValueList<KoPictureKey> keys );
  111.  
  112.     bool saveOasisToStore( KoStore *store, QValueList<KoPictureKey> keys, KoXmlWriter* manifestWriter );
  113.  
  114.  
  115.     typedef QMap<KoPictureKey, QString> StoreMap;
  116.     /**
  117.      * Read the <PICTURES>, <PIXMAPS> or <CLIPARTS> tag, and save the result (key<->store-filename associations)
  118.      * into the QMap. You may want to 'new' a QMap in loadXML, and to use and then delete
  119.      * it in completeLoading (to save memory).
  120.      *
  121.      * @param pixmapsElem the <PICTURES>, <PIXMAPS> or <CLIPARTS> element
  122.      */
  123.     StoreMap readXML( QDomElement &pixmapsElem );
  124.  
  125.     /**
  126.      * Helper method for @ref #readFromStore
  127.      */
  128.     void readXML( QDomElement& pixmapsElem, QMap <KoPictureKey, QString>& map );
  129.  
  130.     /**
  131.      * Read all pictures from the store, into this collection
  132.      * The map comes from @ref #readXML, and is used to find which pictures
  133.      * to load, and which key to associate them.
  134.      */
  135.     void readFromStore( KoStore * store, const StoreMap & storeMap );
  136.  
  137.     /**
  138.      * @deprecated
  139.      * KPresenter needs to use the same code for loading images from a collection and
  140.      * for loading images from disk.
  141.      *
  142.      * @param fileName the name of the file to read from disk if needed
  143.      * @param dateTime the date and time
  144.      *
  145.      * Formerly, an invalid date/time meant to read the file from disk. This is not the case anymore.
  146.      */
  147.     KoPicture findOrLoad(const QString& fileName, const QDateTime& dateTime);
  148.  
  149.     /**
  150.      * Return filename as url for picture
  151.      *
  152.      */
  153.     QString getOasisFileName(const KoPicture& picture) const;
  154.  
  155.     /**
  156.      * Call it before to save Oasis file
  157.      */
  158.     void assignUniqueIds();
  159.  
  160.  
  161. private:
  162.     /**
  163.      * @internal
  164.      */
  165.     QString getFileName(const Type pictureType, KoPicture& picture, int& counter);
  166.  
  167.     class Private;
  168.     Private* d;
  169. };
  170.  
  171. #endif /* __koPictureCollection_h_- */
  172.